<!--
* description: 案例详情
* author: wangjuan
* createdDate: 2021-3-4
-->
<template>
  <section class="editStoreReturnRegistration">
    <el-dialog
      v-dialogDrag
      :visible.sync="curPopupsVisible"
      :title="textMap"
      :append-to-body="true"
      width="70%"
      :close-on-click-modal="false"
      @opened="openDialog"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="textMap"
        :style-type="$store.state.app.dialogType"
      />
      <div class="filter-container filter-title">基本信息</div>
      <div class="filter-container filter-params">
        <el-row id="elrow" ref="vailComponentList1" :gutter="24">
          <component
            :is="comp.component"
            v-for="comp in tableComponents1.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :span="comp.span || 6"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>
      <div class="filter-container filter-title">车辆信息</div>
      <div class="filter-container filter-params">
        <el-row id="elrow" ref="vailComponentList2" :gutter="24">
          <component
            :is="comp.component"
            v-for="comp in tableComponents2.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :span="comp.span || 6"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>
      <div class="filter-container filter-title">车辆信息</div>
      <div class="filter-container filter-params">
        <el-row id="elrow" ref="vailComponentList3" :gutter="24">
          <component
            :is="comp.component"
            v-for="comp in tableComponents3.filter((o) => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds || ''"
            :code="formField[comp.codeField]"
            :disabled="comp.disabled"
            :is-require="comp.isRequire"
            :span="comp.span || 6"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :o-fields="comp.oFields"
            @changeCode="getComponentCode"
          />
        </el-row>
      </div>
      <tab-tables ref="tabs" :tab-panes="tabPanes" :tab-options="optionTab" />
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { formMixins } from '@/components/mixins/formMixins'
import tabTables from '@/views/se/serviceActivities/serviceRelease/components/tabTables'
import { orgApis } from '@/api/caseManagementQuery'

export default {
  components: {
    tabTables,
    dialogHeader: () => import('@/components/dialogHeader')
  },

  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins, formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    // 从网格传入的编辑行数据(json)
    dynamicEditRowData: { type: Object, default: function() { return {} } }
  },

  data() {
    return {
      tableComponents: [],
      tableComponents1: [
        {
          compKey: 'compKey0',
          labelName: '案例编码：',
          codeField: 'reportCode',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey1',
          labelName: '提报日期：',
          codeField: 'submitDate',
          component: () => import('@/components/org/datePicker/datePicker'),
          type: 'datePicker',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey2',
          labelName: '门店编码：',
          codeField: 'dlrCode',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey3',
          labelName: '门店名称：',
          codeField: 'dlrFullName',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey4',
          labelName: '维修工单：',
          codeField: 'repairOrderCode',
          isMul: false,
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey5',
          labelName: '重要程度：',
          codeField: 'reportLevel',
          isMul: false,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          disabled: true,
          isRequire: true
        },
        {
          compKey: 'compKey6',
          labelName: '案例状态：',
          codeField: 'status',
          isMul: false,
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          disabled: true
        }
      ],
      tableComponents2: [
        {
          compKey: 'compKey7',
          labelName: 'VIN码：',
          codeField: 'vin',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true,
          isRequire: true
        },
        {
          compKey: 'compKey8',
          labelName: '车辆型号：',
          codeField: 'carConfigCn',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey9',
          labelName: '车系：',
          codeField: 'carSeriesCn',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey10',
          labelName: '销售日期：',
          codeField: 'saleDate',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey11',
          labelName: '生产日期：',
          codeField: 'produceDate',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        }
      ],
      tableComponents3: [
        {
          compKey: 'compKey12',
          labelName: '故障编码：',
          codeField: 'faultCode',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          isRequire: true,
          disabled: true
        },
        {
          compKey: 'compKey13',
          labelName: '故障部位：',
          codeField: 'faultPartName',
          component: () => import('@/components/org/LookupValue'),
          type: 'dropdownList',
          isMust: true,
          disabled: true,
          isRequire: true
        },
        {
          compKey: 'compKey14',
          labelName: '故障日期：',
          codeField: 'faultDate',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          isRequire: true,
          disabled: true
        },
        {
          compKey: 'compKey15',
          labelName: '主故障件号：',
          codeField: 'mainPartCode',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          isRequire: true,
          disabled: true
        },
        {
          compKey: 'compKey16',
          labelName: '主故障件名称：',
          codeField: 'mainPartName',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey21',
          labelName: '提报人：',
          codeField: 'submitEmpid',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey22',
          labelName: '提报人电话：',
          codeField: 'empName',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true
        },
        {
          compKey: 'compKey17',
          labelName: '主题：',
          codeField: 'topic',
          component: () => import('@/components/org/commonInput'),
          type: 'inputText',
          isMust: true,
          disabled: true,
          span: 24
        },
        {
          compKey: 'compKey18',
          labelName: '故障描述：',
          codeField: 'faultDesc',
          component: () => import('@/components/org/commonInput/textareaInput'),
          type: 'inputText',
          isMust: true,
          disabled: true,
          span: 24
        },
        {
          compKey: 'compKey19',
          labelName: '维修方案：',
          codeField: 'repairMethod',
          component: () => import('@/components/org/commonInput/textareaInput'),
          type: 'inputText',
          isMust: true,
          disabled: true,
          span: 24
        }
      ],
      tabPanes: [
        {
          index: 0,
          name: 'fileInfo',
          title: '附件',
          tables: [
            {
              name: 'tabOne',
              tableData: [],
              hasSelection: false,
              height: '300',
              tableLoading: false,
              tableCols: [
                { prop: 'fileName', label: '附件名称' },
                { prop: 'fileSite', label: '附件地址' }
              ]
            }
          ]
        },
        {
          index: 1,
          name: 'auditInfo',
          title: '审核历史',
          tables: [
            {
              name: 'tabOne',
              tableData: [],
              hasSelection: false,
              height: '300',
              tableLoading: false,
              tableCols: [
                { prop: 'checkEmpid', label: '审核人' },
                { prop: 'checkDate', label: '审核时间' }
              ]
            }
          ]
        }
      ],
      optionTab: {
        activeName: 'fileInfo',
        tabClick: (tab, event) => {}
      },
      // 标题
      textMap: '案例详情',

      formField: {}
    }
  },

  created() {
    this.tableComponents = [...this.tableComponents1, ...this.tableComponents2, ...this.tableComponents3]
  },

  methods: {
    openDialog() {
      this.formField = this.dynamicEditRowData
      const queryObj = {
        // 保存mutation
        type: 'query',
        // api配置
        apiConfig: orgApis.queryTechnicalSupportDetail,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          reportId: this.dynamicEditRowData.reportId
        }
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.formField = response.rows[0]
          this.tabPanes[0].tables[0].tableData = response.rows[0].fujianInfo
          this.tabPanes[1].tables[0].tableData = response.rows[0].shenheInfo
        }
      })
    },
    closeEdit() {
      this.$emit('update:popupsVisible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.btns-container {
  width: 100%;
  height: 30px;
  padding: 0 20px;
  background-color: #fff;
  .el-button {
    float: right;
    margin-left: 10px;
  }
}
  .filter-title{
    font-size: 18px;
    font-weight: bolder;
  }
  .filter-container.filter-title::before{
    border-left: 4px solid #0075FF;
    padding-right: 10px;
    height: 20px;
    left: 0px;
    top: 4px;
  }
</style>

